package com.wo.android.pockybill;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

/**
 * 控制器基礎
 * 
 * @author ING
 * 
 */
public abstract class BaseActivity extends Activity implements
		DialogInterface.OnClickListener {
	private Builder errorDialog = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		errorDialog = new AlertDialog.Builder(this);

		errorDialog.setTitle(this.getString(R.string.warm));

		errorDialog
				.setNegativeButton(this.getString(android.R.string.ok), this);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
	}

	public void onWarm(final String msg) {
		this.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				errorDialog.setMessage(msg);
				errorDialog.show();

			}
		});
	}

	public void onError(final String msg) {

		this.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				errorDialog.setMessage(msg);
				errorDialog.show();

			}
		});

	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		Intent i = new Intent(this, this.toWhenError());
		this.startActivity(i);
		this.finish();
	}

	public abstract Class<? extends BaseActivity> toWhenError();
}
